import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'node:path'
// 按需导入
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import viteCompression from 'vite-plugin-compression'
import { viteMockServe } from 'vite-plugin-mock'
import commonjs from 'vite-plugin-commonjs'
import VueSetupExtend from 'vite-plugin-vue-setup-extend'
// import mockDevServerPlugin from 'vite-plugin-mock-dev-server'
export default defineConfig({
	base: './',
	server: {
		host: '0.0.0.0'
	},
	define: {
		__VUE_OPTIONS_API__: false
	},
	plugins: [
		vue(),
		commonjs(),
		AutoImport({
			resolvers: [ElementPlusResolver()],
			imports: ['vue', 'vue-router']
		}),
		Components({
			resolvers: [ElementPlusResolver()]
		}),
		VueSetupExtend(),
		viteCompression({
			verbose: true,
			disable: false,
			threshold: 10240,
			algorithm: 'gzip',
			ext: '.gz'
		}),
		viteMockServe({
			mockPath: './src/api/mock',
			force: false,
			mocks: [
				{
					url: '/api/data',
					method: 'get',
					response: {
						code: 200,
						data: { message: 'Hello from mock API!' }
					}
				},
				{
					url: 'https://shopapi.ktvit.cn', // 也可以拦截带有 http 的请求
					method: 'get',
					response: {
						code: 200,
						data: { message: 'Hello from mock API with http!' }
					}
				}
			]
		})
	],
	css: {
		preprocessorOptions: {
			scss: {
				additionalData: "@import '@/style/var.scss';"
			}
		}
	},
	resolve: {
		alias: {
			'@': path.resolve(__dirname, './src')
		},
		extensions: ['.js', '.jsx', '.json', '.vue']
	}
})
